export function goLogin(optins = {}) {
    let { information = false, tagid = 86, handle, cancel} = optins;
	let contents;
	if(information){
		contents = "您还未授权，授权后后可查看！"
	}else{
		contents = "未登录或登录失效请登录！"
	}
    const pages = getCurrentPages();
    if (!pages.length) {
        return false
    }
    const page = pages[pages.length - 1];
    if (page.route == "pages/login/index") {
        return false
    }

    uni.showModal({
        title: "提示",
        content: contents,
        cancelText: "取消",
        confirmText: information?"去授权":"去登录",
        confirmColor: "#BFA559",
        success:(res) => {
            if (res.confirm) {
				if(information){
                    uni.navigateTo({
                        url:'/pages/login/information?'+ parameter
                    })
				}else{
                    uni.navigateTo({
                        url:'/pages/login/index?tag_id='+tagid
                    })
				}
            } else if (res.cancel) {
                if(cancel) cancel();
            }
        },
        complete() {
            if(handle) handle();
        }

    });

}
export function getQrcodeOptions(){
    let optins = wx.getEnterOptionsSync();
    //获取utm参数
    let parames = {};
    if(optins.query.scene){
        let scene = decodeURIComponent(optins.query.scene);
        scene.split("&").forEach(item => {
            let  key = item.split('=')[0];
            let value = item.split('=')[1];
            parames[key] = value;
        });
        return parames;
    }else{
        return optins.query;
    }

}
export function getQueryParam(link, query){
    let parames = {};
    let url = link.split('?')[1];
    if(url){
        url.split("&").forEach(item => {
            let  key = item.split('=')[0];
            let value = item.split('=')[1];
            parames[key] = value;
        });
        return query ? parames[query] : parames;
    }
}
export function formatDate(value, Format) {
    console.log(value, Format, ' value, Format')
    let Formats = Format || 'yyyy-MM-dd'
    let date = value ? new Date(value.replace(/[-.]/g,'/')) : new Date()
    let obj = {
        yyyy: date.getFullYear(),
        MM: date.getMonth() + 1,
        dd: date.getDate(),
        hh: date.getHours(),
        mm: date.getMinutes()
    }
    let {MM, dd, hh, mm } = obj
    obj.MM = MM < 10 ? "0" + MM : MM;
    obj.dd = dd < 10 ? "0" + dd : dd;
    obj.hh = hh < 10 ? "0" + hh : hh;
    obj.mm = mm < 10 ? "0" + mm : mm;

    for (let i in obj) {
        Formats = Formats.replace(i, obj[i])
    }
    return Formats
}
export function deepClone(obj) {
    function isObject(obj){
        return typeof obj==="object" && typeof obj!=="null"
    }
    if(!isObject(obj)){
        throw new Error("输入参数不是对象")
    }
    let res=Array.isArray(obj)?[...obj]:{...obj};
    Object.keys(res).forEach((key)=>{
        res[key]=isObject(res[key])?deepClone(res[key]):res[key]
    })
    return res 
}

export function arrayFilter(arr, func){
	var res = new Array;
	arr.forEach(element =>{
		if (func(element)){
			res.push(element);
		}
	}
	);
	
	return res;
}